# -*- coding:utf-8 -*-
import json

import requests
from loguru import logger

from constant.request_contants import REQUEST_GET, REQUEST_POST


class ParseEngine:
    def __init__(self, target_api):
        self.target_api = target_api

    def parse(self, data):
        result = ""
        if self.target_api.method == REQUEST_GET:
            result = requests.get(url=self.target_api.url, params=data).content
        elif self.target_api.method == REQUEST_POST:
            result = requests.post(url=self.target_api.url, data=data).content
        else:
            logger.info("unknown method")
        return result

    def batch_parse(self, data_list):
        result_list = []
        for data in data_list:
            result_list.append(self.parse(data))
        return result_list